﻿
@{
    ViewBag.Title = "工程量明细表";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>工程量明细表-@ViewBag.ProjectInfoMap["Name"]</legend>
</fieldset>

<div>
    <form class="layui-form" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">搜索</label>
            <input type="text" id="SearchText" name="Title1" required lay-verify="required" onkeypress="getKey()" placeholder="输入名称" class="layui-input" style="width:300px;float:left;">
            <input type="text" value="" style="display:none" />
            <button type="button" class="layui-btn layui-btn-normal" style="float:left;" onclick="SearchFunc()"><i class="layui-icon">&#xe615;</i></button>
            <button type="button" class="layui-btn" style="float:left;" id="BtnAdd"><i class="layui-icon">&#xe61f;</i>新增</button>
            <button type="button" class="layui-btn layui-btn-danger" style="float:left;" id="BtnQuote"><i class="layui-icon">&#xe61f;</i>引入</button>
            <button type="button" class="layui-btn layui-btn-normal" style="float:left;" id="BatchDel"><i class="layui-icon">&#xe640;</i>批量删除</button>
        </div>
    </form>
</div>
<div class="layui-tab" lay-filter="tabFilter">
    <ul class="layui-tab-title">
        <li class="layui-this">外线</li>
        <li>开闭所部分</li>
        <li>公配部分</li>
        <li>专配部分</li>
        <li>土建</li>
        <li>全部</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table id="WX_WorkQuantitiesTable" lay-filter="WX_WorkQuantitiesTableFilter"></table>
        </div>
        <div class="layui-tab-item">
            <table id="KBS_WorkQuantitiesTable" lay-filter="KBS_WorkQuantitiesTableFilter"></table>
        </div>
        <div class="layui-tab-item">
            <table id="GP_WorkQuantitiesTable" lay-filter="GP_WorkQuantitiesTableFilter"></table>
        </div>
        <div class="layui-tab-item">
            <table id="ZP_WorkQuantitiesTable" lay-filter="ZP_WorkQuantitiesTableFilter"></table>
        </div>
        <div class="layui-tab-item">
            <table id="TJ_WorkQuantitiesTable" lay-filter="TJ_WorkQuantitiesTableFilter"></table>
        </div>
        <div class="layui-tab-item">
            <table id="QB_WorkQuantitiesTable" lay-filter="QB_WorkQuantitiesTableFilter"></table>
        </div>
    </div>
</div>

<div id="EditLayer" style="display:none;">
    <form class="layui-form" id="EditFrom" style="margin-top:10px;">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>新增工程量</legend>
        </fieldset>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" name="Name" value="" placeholder="必填" required lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">到货时间</label>
                <div class="layui-input-inline" style="width:120px;">
                    <input type="text" name="GetTimeMemo" value="" placeholder="必填" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">成本类型</label>
                <div class="layui-input-inline" style="width:120px;">
                    <select name="CostType">
                        <option value="设备">设备</option>
                        <option value="材料">材料</option>
                        <option value="安装">安装</option>
                        <option value="土建">土建</option>
                    </select>
                </div>

            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">报价图纸量</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="BJTZNum" value="" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">报价实际量</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="BJSJNum" value="" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">测算图纸量</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="CSTZNum" value="" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">测算实际量</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="CSSJNum" value="" required class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">报价合计</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="BJMoney" value="" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">测算合计</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="CSMoney" value="" required class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">实际收方量</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="SJSFNum" value="" placeholder="必填" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">差异说明</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" name="DifferentMemo" value="" placeholder="必填" required class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">采购要求</label>
                <div class="layui-input-inline" style="width:180px;">
                    <input type="text" name="PurchaseMemo" value="" placeholder="必填" required class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
            </div>
            <button type="button" class="layui-btn" id="BtnEditFromSave">保存</button>
        </div>
        <button type="submit" id="mysubmit" class="layui-btn" lay-submit lay-filter="formVerify" style="display:none;">立即提交</button>
    </form>
</div>



<script type="text/javascript">
    var table;
    var TabIndex = 0;
    var PreEstUserId =@ViewBag.PreEstUserId;
    var PreEstUserCSId =@ViewBag.PreEstUserCSId;
    var ProjectId=@ViewBag.ProjectId;
    layui.use(['form', 'table', 'upload', 'layer', 'element'], function () {
        var element = layui.element;
        var form = layui.form;
        table = layui.table;
        var tab = parent.tab;
        var layer = layui.layer;
        var index;
        var layerIndex;
        var layerDivBJCopyIndex;
        var layerDivCSCopyIndex;
        var ProjectType = "";
        var ProjectName = "";
        var ProjectCode = "";
        var IsValidate = 0;

        //监听选项卡切换
        element.on('tab(tabFilter)', function (data) {
            //index从0开始
            TabIndex = data.index;
        });

        //拦截form提交消息
        form.on('submit(formVerify)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            IsValidate = 1;
            return false;
        });

        $("#BtnAdd").on("click", function () {
            if (TabIndex == 4) {
                return;
            }
            layerindex = layer.open({
                type: 1,
                title: ['新增', 'font-size:18px;'],
                area: ['1000px', '400px'],
                content: $("#EditLayer"),  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                success: function (layero, index) {
                    $("#EditFrom input[name='CoordFeeId']").val("");
                }
            });
        });

        $("#BtnEditFromSave").on("click", function () {

            $("#mysubmit").click();
            if (IsValidate == 1) {
                IsValidate = 0;
            } else {
                return;
            }
            var obj = $("#EditFrom").serializeArray();
            var data = {};
            $.each(obj, function (i, v) {
                data[v.name] = v.value;
            });
            data["PreEstUserId"] = PreEstUserId;
            data["PreEstUserCSId"] = PreEstUserCSId;
            data["ProjectId"] = ProjectId;
            if (TabIndex == 0) {
                data["Type"] = "外线";
            }
            if (TabIndex == 1) {
                data["Type"] = "开闭所";
            }
            if (TabIndex == 2) {
                data["Type"] = "公配";
            }
            if (TabIndex == 3) {
                data["Type"] = "专配";
            }
            if (TabIndex == 4) {
                data["Type"] = "土建";
            }
            //delete data["CoordFeeId"];
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesAdd",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('添加成功', { icon: 6, time: 1000 });
                        layer.close(layerindex);
                        if (TabIndex == 0) {
                            table.reload("WX_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 1) {
                            table.reload("KBS_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 2) {
                            table.reload("GP_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 3) {
                            table.reload("ZP_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 4) {
                            table.reload("TJ_WorkQuantitiesTable", {});
                        }
                        
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });

        $("#BatchDel").on("click", function () {
            var checkStatus;
            if (TabIndex == 0) {
                checkStatus = table.checkStatus('WX_WorkQuantitiesTable');
            }
            if (TabIndex == 1) {
                checkStatus = table.checkStatus('KBS_WorkQuantitiesTable');
            }
            if (TabIndex == 2) {
                checkStatus = table.checkStatus('GP_WorkQuantitiesTable');
            }
            if (TabIndex == 3) {
                checkStatus = table.checkStatus('ZP_WorkQuantitiesTable');
            }
            if (TabIndex == 4) {
                checkStatus = table.checkStatus('TJ_WorkQuantitiesTable');
            }
            if (TabIndex == 5) {
                checkStatus = table.checkStatus('QB_WorkQuantitiesTable');
            }
            var data = checkStatus.data;
            if (data.length < 1) {
                layer.msg('至少选择一行数据', { icon: 3, time: 1500 });
                return;
            }
            var arr = new Array();
            for (var i = 0; i < data.length; i++) {
                arr[i] = data[i].WorkQuantitiesId;
            }

            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesBatchDel",
                //contentType: "application/json",
                //dataType: "json",
                async: false,
                data: { "WorkQuantitiesId": arr },
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('删除成功"', { icon: 6, time: 1000 });
                        if (TabIndex == 0) {
                            table.reload("WX_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 1) {
                            table.reload("KBS_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 2) {
                            table.reload("GP_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 3) {
                            table.reload("ZP_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 4) {
                            table.reload("TJ_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 5) {
                            table.reload("QB_WorkQuantitiesTable", {});
                        }
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });

        //引入
        $("#BtnQuote").on("click", function () {
            //全部 不引入
            if (TabIndex == 5) {
                return;
            }
            var TabType = "";
            var TypeName = "";
            if (TabIndex == 0) {
                TabType = "WX";
                TypeName = "外线";
            }
            if (TabIndex == 1) {
                TabType = "KBS";
                TypeName = "开闭所";
            }
            if (TabIndex == 2) {
                TabType = "GP";
                TypeName = "公配";
            }
            if (TabIndex == 3) {
                TabType = "ZP";
                TypeName = "专配";
            }
            if (TabIndex == 4) {
                TabType = "TJ";
                TypeName = "土建";
            }
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesBatchAdd",
                //contentType: "application/json",
                //dataType: "json",
                async: false,
                data: { "TabType": TabType, "TypeName": TypeName, "PreEstUserCSId": PreEstUserCSId, "PreEstUserId": PreEstUserId, "ProjectId": ProjectId },
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('添加成功"', { icon: 6, time: 1000 });
                        if (TabIndex == 0) {
                            table.reload("WX_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 1) {
                            table.reload("KBS_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 2) {
                            table.reload("GP_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 3) {
                            table.reload("ZP_WorkQuantitiesTable", {});
                        }
                        if (TabIndex == 4) {
                            table.reload("TJ_WorkQuantitiesTable", {});
                        }
                    } else {
                        alert(msg.result);
                    }
                }
            });



        });


        ///////////////////////////////////////////////////////////////////////////////////
        //外线
        table.render({
            elem: '#WX_WorkQuantitiesTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/WorkQuantitiesTableRequest' //数据接口
            , page: true //开启分页
            , where: {
                SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='外线' and ProjectId=" + ProjectId +
                    " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId }
            , limits: [100, 500, 1000]
            , limit:100
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'CostType', title: '成本类型', width:90 }
                , { field: 'Name', title: '名称', width: 150, edit: 'text' }
                , { field: 'BJTZNum', title: '报价图纸量', width: 100, edit: 'text' }
                , { field: 'BJSJNum', title: '报价实际量', width: 100, edit: 'text' }
                , { field: 'CSTZNum', title: '测算图纸量', width: 100, edit: 'text' }
                , { field: 'CSSJNum', title: '测算实际量', width: 100, edit: 'text' }
                , { field: 'SJSFNum', title: '实际收方量', width: 100, edit: 'text' }
                , { field: 'BJMoney', title: '报价合计', width: 100, edit: 'text' }
                , { field: 'CSMoney', title: '测算合计', width: 100, edit: 'text' }
                , { field: 'DifferentMemo', title: '差异说明', width: 200, edit: 'text' }
                , { field: 'PurchaseMemo', title: '采购要求', width: 100, edit: 'text' }
                , { field: 'GetTimeMemo', title: '到货时间', width: 100, edit: 'text' }

            ]]
        });

        table.on('edit(WX_WorkQuantitiesTableFilter)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            //console.log(obj.value); //得到修改后的值
            //console.log(obj.field); //当前编辑的字段名
            //console.log(obj.data); //所在行的所有相关数据  
            var data = obj.data;
            var field = obj.field;
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(obj.data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        table.reload('WX_WorkQuantitiesTable');
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });



        //开闭所
        table.render({
            elem: '#KBS_WorkQuantitiesTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/WorkQuantitiesTableRequest' //数据接口
            , page: true //开启分页
            , where: {
                SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='开闭所' and ProjectId=" + ProjectId +
                    " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
            }
            , limits: [100, 500, 1000]
            , limit: 100
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'CostType', title: '成本类型', width: 90 }
                , { field: 'Name', title: '名称', width: 150, edit: 'text'}
                , { field: 'BJTZNum', title: '报价图纸量', width: 100, edit: 'text'}
                , { field: 'BJSJNum', title: '报价实际量', width: 100, edit: 'text'}
                , { field: 'CSTZNum', title: '测算图纸量', width: 100, edit: 'text'}
                , { field: 'CSSJNum', title: '测算实际量', width: 100, edit: 'text'}
                , { field: 'SJSFNum', title: '实际收方量', width: 100, edit: 'text' }
                , { field: 'BJMoney', title: '报价合计', width: 100, edit: 'text' }
                , { field: 'CSMoney', title: '测算合计', width: 100, edit: 'text' }
                , { field: 'DifferentMemo', title: '差异说明', width: 200, edit: 'text'}
                , { field: 'PurchaseMemo', title: '采购要求', width: 100, edit: 'text'}
                , { field: 'GetTimeMemo', title: '到货时间', width: 100, edit: 'text'}

            ]]
        });

        table.on('edit(KBS_WorkQuantitiesTableFilter)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            //console.log(obj.value); //得到修改后的值
            //console.log(obj.field); //当前编辑的字段名
            //console.log(obj.data); //所在行的所有相关数据  
            var data = obj.data;
            var field = obj.field;
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(obj.data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        table.reload('KBS_WorkQuantitiesTable');
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });



        //公配
        table.render({
            elem: '#GP_WorkQuantitiesTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/WorkQuantitiesTableRequest' //数据接口
            , page: true //开启分页
            , where: {
                SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='公配' and ProjectId=" + ProjectId +
                    " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
            }
            , limits: [100, 500, 1000]
            , limit: 100
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'CostType', title: '成本类型', width: 90 }
                , { field: 'Name', title: '名称', width: 150, edit: 'text' }
                , { field: 'BJTZNum', title: '报价图纸量', width: 100, edit: 'text' }
                , { field: 'BJSJNum', title: '报价实际量', width: 100, edit: 'text' }
                , { field: 'CSTZNum', title: '测算图纸量', width: 100, edit: 'text' }
                , { field: 'CSSJNum', title: '测算实际量', width: 100, edit: 'text' }
                , { field: 'SJSFNum', title: '实际收方量', width: 100, edit: 'text' }
                , { field: 'BJMoney', title: '报价合计', width: 90, edit: 'text' }
                , { field: 'CSMoney', title: '测算合计', width: 90, edit: 'text' }
                , { field: 'DifferentMemo', title: '差异说明', width: 200, edit: 'text' }
                , { field: 'PurchaseMemo', title: '采购要求', width: 100, edit: 'text' }
                , { field: 'GetTimeMemo', title: '到货时间', width: 100, edit: 'text' }

            ]]
        });

        table.on('edit(GP_WorkQuantitiesTableFilter)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            //console.log(obj.value); //得到修改后的值
            //console.log(obj.field); //当前编辑的字段名
            //console.log(obj.data); //所在行的所有相关数据  
            var data = obj.data;
            var field = obj.field;
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(obj.data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        table.reload('GP_WorkQuantitiesTable');
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });



        //专配
        table.render({
            elem: '#ZP_WorkQuantitiesTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/WorkQuantitiesTableRequest' //数据接口
            , page: true //开启分页
            , where: {
                SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='专配' and ProjectId=" + ProjectId +
                    " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
            }
            , limits: [100, 500, 1000]
            , limit: 100
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'CostType', title: '成本类型', width: 90 }
                , { field: 'Name', title: '名称', width: 150, edit: 'text' }
                , { field: 'BJTZNum', title: '报价图纸量', width: 100, edit: 'text' }
                , { field: 'BJSJNum', title: '报价实际量', width: 100, edit: 'text' }
                , { field: 'CSTZNum', title: '测算图纸量', width: 100, edit: 'text' }
                , { field: 'CSSJNum', title: '测算实际量', width: 100, edit: 'text' }
                , { field: 'SJSFNum', title: '实际收方量', width: 100, edit: 'text' }
                , { field: 'BJMoney', title: '报价合计', width: 100, edit: 'text' }
                , { field: 'CSMoney', title: '测算合计', width: 100, edit: 'text' }
                , { field: 'DifferentMemo', title: '差异说明', width: 200, edit: 'text' }
                , { field: 'PurchaseMemo', title: '采购要求', width: 100, edit: 'text' }
                , { field: 'GetTimeMemo', title: '到货时间', width: 100, edit: 'text' }

            ]]
        });

        table.on('edit(ZP_WorkQuantitiesTableFilter)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            //console.log(obj.value); //得到修改后的值
            //console.log(obj.field); //当前编辑的字段名
            //console.log(obj.data); //所在行的所有相关数据  
            var data = obj.data;
            var field = obj.field;
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(obj.data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        table.reload('ZP_WorkQuantitiesTable');
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });

        //土建
        table.render({
            elem: '#TJ_WorkQuantitiesTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/WorkQuantitiesTableRequest' //数据接口
            , page: true //开启分页
            , where: {
                SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='土建' and ProjectId=" + ProjectId +
                    " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
            }
            , limits: [100, 500, 1000]
            , limit: 100
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'CostType', title: '成本类型', width: 90 }
                , { field: 'Name', title: '名称', width: 150, edit: 'text' }
                , { field: 'BJTZNum', title: '报价图纸量', width: 100, edit: 'text' }
                , { field: 'BJSJNum', title: '报价实际量', width: 100, edit: 'text' }
                , { field: 'CSTZNum', title: '测算图纸量', width: 100, edit: 'text' }
                , { field: 'CSSJNum', title: '测算实际量', width: 100, edit: 'text' }
                , { field: 'SJSFNum', title: '实际收方量', width: 100, edit: 'text' }
                , { field: 'BJMoney', title: '报价合计', width: 100, edit: 'text' }
                , { field: 'CSMoney', title: '测算合计', width: 100, edit: 'text' }
                , { field: 'DifferentMemo', title: '差异说明', width: 200, edit: 'text' }
                , { field: 'PurchaseMemo', title: '采购要求', width: 100, edit: 'text' }
                , { field: 'GetTimeMemo', title: '到货时间', width: 100, edit: 'text' }

            ]]
        });

        table.on('edit(TJ_WorkQuantitiesTableFilter)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            //console.log(obj.value); //得到修改后的值
            //console.log(obj.field); //当前编辑的字段名
            //console.log(obj.data); //所在行的所有相关数据  
            var data = obj.data;
            var field = obj.field;
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(obj.data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        table.reload('TJ_WorkQuantitiesTable');
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });


        //全部
        table.render({
            elem: '#QB_WorkQuantitiesTable'
            , method: 'post'
            //, height: 315
            , url: '/Estimate/WorkQuantitiesTableRequest' //数据接口
            , page: true //开启分页
            , where: {
                SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and ProjectId=" + ProjectId +
                    " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
            }
            , limits: [100, 500, 1000]
            , limit: 100
            , cols: [[ //表头
                { type: 'checkbox' }
                , { field: 'CostType', title: '成本类型', width: 90 }
                , { field: 'Name', title: '名称', width: 150, edit: 'text' }
                , { field: 'BJTZNum', title: '报价图纸量', width: 100, edit: 'text' }
                , { field: 'BJSJNum', title: '报价实际量', width: 100, edit: 'text' }
                , { field: 'CSTZNum', title: '测算图纸量', width: 100, edit: 'text' }
                , { field: 'CSSJNum', title: '测算实际量', width: 100, edit: 'text' }
                , { field: 'SJSFNum', title: '实际收方量', width: 100, edit: 'text' }
                , { field: 'BJMoney', title: '报价合计', width: 100, edit: 'text' }
                , { field: 'CSMoney', title: '测算合计', width: 100, edit: 'text' }
                , { field: 'DifferentMemo', title: '差异说明', width: 200, edit: 'text' }
                , { field: 'PurchaseMemo', title: '采购要求', width: 100, edit: 'text' }
                , { field: 'GetTimeMemo', title: '到货时间', width: 100, edit: 'text' }

            ]]
        });

        table.on('edit(QB_WorkQuantitiesTableFilter)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            //console.log(obj.value); //得到修改后的值
            //console.log(obj.field); //当前编辑的字段名
            //console.log(obj.data); //所在行的所有相关数据  
            var data = obj.data;
            var field = obj.field;
            $.ajax({
                type: "POST",
                url: "/Estimate/WorkQuantitiesUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(obj.data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        table.reload('ZP_WorkQuantitiesTable');
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });





    });


    //回车键
    function getKey() {
        if (event.keyCode == 13) {
            SearchFunc();
        }
    }

    function SearchFunc() {
        var text = $("#SearchText").val();
        if (text == "") {
            if (TabIndex == 0) {
                table.reload("WX_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='外线' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
                    }
                });
            }
            if (TabIndex == 1) {
                table.reload("KBS_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='开闭所' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
                    }
                });
            }
            if (TabIndex == 2) {
                table.reload("GP_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='公配' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
                    }
                });
            }
            if (TabIndex == 3) {
                table.reload("ZP_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='专配' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
                    }
                });
            }
            if (TabIndex == 4) {
                table.reload("QB_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId
                    }
                });
            }
        }
        else {
            if (TabIndex == 0) {
                table.reload("WX_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='外线' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId + "and Name like'%" + text + "%'"
                    }
                });
            }
            if (TabIndex == 1) {
                table.reload("KBS_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='开闭所' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId + "and Name like'%" + text + "%'"
                    }
                });
            }
            if (TabIndex == 2) {
                table.reload("GP_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='公配' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId + "and Name like'%" + text + "%'"
                    }
                });
            }
            if (TabIndex == 3) {
                table.reload("ZP_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and Type='专配' and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId + "and Name like'%" + text + "%'"
                    }
                });
            }
            if (TabIndex == 4) {
                table.reload("QB_WorkQuantitiesTable", {
                    where: {
                        SortName: "WorkQuantitiesId", Order: "Desc", Condition: " and ProjectId=" + ProjectId +
                            " and PreEstUserCSId=" + PreEstUserCSId + " and PreEstUserId=" + PreEstUserId + "and Name like'%" + text + "%'"
                    }
                });
            }
        }
    }


</script>
